﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Website/Site1.Master" AutoEventWireup="true" CodeBehind="PurchaseHistory.aspx.cs" Inherits="ChicagoDealsN.Website.PurchaseHistory" %>
<%@ Import Namespace="ChicagoDealsN" %>
<script runat="server">
    bool flag = false;
    public void Page_Load(object sender, EventArgs e)
    {
        
        BizPurchaseHistory bd = new BizPurchaseHistory();
        try
        {
            DataUser du = Session["UserDet"] as DataUser;
            if (du != null)
            {
                System.Data.DataTable ret = bd.getPurchaseHistory(du.User_Id);
                if (ret != null)
                {
                    rpt_PurchaseHistory.DataSource = ret;
                    rpt_PurchaseHistory.DataBind();
                    rpt_PurchaseHistory.Visible = true;
                    confirmation.Text = "Here is your purchase history!";
                }
                else { confirmation.Text = "nothing found!"; }
            }
        }
        catch (Exception ex)
        {
            confirmation.Text = "Somthing went wrong!<br/>"+ex.ToString();
        }
    }

    private bool IsLoggedIn()
    {
        return (Session["UserDet"] != null) ? true : false;
    }
    
    private string CheckIfRedeemed(int value)
    {
        if (value != 0)
        {
            flag = true;
            return "Yes";
        }
        else {
            flag = false;
            return "No";
        }
    }
    private string checkFlag(string red_date)
    {
        if (flag)
            return red_date;
        else
            return "N.A.";
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="conirmation-container"><asp:Label ID="confirmation" runat="server" /></div>
    <asp:Repeater id="rpt_PurchaseHistory" runat="server" Visible="false">
        <HeaderTemplate>
            <table class="table-style1" cellpadding="4" cellspacing="0">
                <tr>
                    <th>Id</th>
                    <th>Name</th>
                    <th>Purchase Date</th>
                    <th>Redeemed</th>
                    <th>Redeem Date</th>
                    <th>Original Price</th>
                    <th>Deal Price</th>
                    <th>Redemption Code</th>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
                <tr>
                    <td><%# (((RepeaterItem)Container).ItemIndex + 1).ToString()%></td>
                    <td><%# DataBinder.Eval(Container.DataItem, "Deal_Title") %></td>
                    <td><%# DataBinder.Eval(Container.DataItem, "Purchased_Date") %></td>
                    <td><%# CheckIfRedeemed(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Redeemed")))%></td>
                    <td><%# checkFlag(DataBinder.Eval(Container.DataItem, "Redeemed_Date").ToString()) %></td>
                    <td><%# DataBinder.Eval(Container.DataItem, "Org_Price") %></td>
                    <td><%# DataBinder.Eval(Container.DataItem, "Deal_Price") %></td>
                    <td><%# DataBinder.Eval(Container.DataItem, "Redeem_Code") %></td>
                </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>